package com.zenithmind.version.pojo.dto;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

/**
 * 仓库统计信息DTO - 遵循单一职责原则，专门用于统计数据传输
 * 
 * @author ZenithMind Team
 * @since 2025-01-09
 */
@Data
@Schema(description = "仓库统计信息DTO")
public class RepositoryStatisticsDTO {

    /**
     * 总仓库数
     */
    @Schema(description = "总仓库数")
    private Integer totalRepositories;

    /**
     * 公开仓库数
     */
    @Schema(description = "公开仓库数")
    private Integer publicRepositories;

    /**
     * 私有仓库数
     */
    @Schema(description = "私有仓库数")
    private Integer privateRepositories;

    /**
     * 内部仓库数
     */
    @Schema(description = "内部仓库数")
    private Integer internalRepositories;

    /**
     * 归档仓库数
     */
    @Schema(description = "归档仓库数")
    private Integer archivedRepositories;

    /**
     * 总提交数
     */
    @Schema(description = "总提交数")
    private Long totalCommits;

    /**
     * 总分支数
     */
    @Schema(description = "总分支数")
    private Long totalBranches;

    /**
     * 总标签数
     */
    @Schema(description = "总标签数")
    private Long totalTags;

    /**
     * 总存储大小（字节）
     */
    @Schema(description = "总存储大小（字节）")
    private Long totalSize;

    /**
     * 活跃仓库数（最近30天有提交）
     */
    @Schema(description = "活跃仓库数（最近30天有提交）")
    private Integer activeRepositories;

    /**
     * 获取格式化的总存储大小
     * 
     * @return 格式化的大小字符串
     */
    public String getFormattedTotalSize() {
        if (totalSize == null || totalSize == 0) {
            return "0 B";
        }
        
        String[] units = {"B", "KB", "MB", "GB", "TB"};
        int unitIndex = 0;
        double sizeValue = totalSize.doubleValue();
        
        while (sizeValue >= 1024 && unitIndex < units.length - 1) {
            sizeValue /= 1024;
            unitIndex++;
        }
        
        return String.format("%.1f %s", sizeValue, units[unitIndex]);
    }
    
    /**
     * 获取活跃度百分比
     * 
     * @return 活跃度百分比
     */
    public double getActivityPercentage() {
        if (totalRepositories == null || totalRepositories == 0) {
            return 0.0;
        }
        int active = activeRepositories != null ? activeRepositories : 0;
        return (double) active / totalRepositories * 100;
    }
    
    /**
     * 获取私有仓库比例
     * 
     * @return 私有仓库比例
     */
    public double getPrivateRepositoryRatio() {
        if (totalRepositories == null || totalRepositories == 0) {
            return 0.0;
        }
        int privateCount = privateRepositories != null ? privateRepositories : 0;
        return (double) privateCount / totalRepositories;
    }
}
